from selenium.webdriver.common.by import By
from pages.base_page import BasePage

class LoginPage(BasePage):
    url = '/crm'
    username_locator = (By.NAME, "name")
    password_locator = (By.NAME, "password")
    btn_locator = (By.NAME, "submit")
    fail_locator = (By.CSS_SELECTOR,'body > div.container > div > div.span4 > div > form > fieldset > div')
    #输入用户名
    def input_username(self, username):
        self.driver.find_element(*self.username_locator).send_keys(username)
    #输入密码
    def input_password(self, password):
        self.driver.find_element(*self.password_locator).send_keys(password)
    #点击登录按钮
    def click_btn(self):
        self.driver.find_element(*self.btn_locator).click()
    #一步到位的方法
    def login(self,username,password):
        self.open()
        self.input_username(username)
        self.input_password(password)
        self.click_btn()
    #断言登录失败
    def login_fail(self):
        return self.driver.find_element(*self.fail_locator).text